package com.eastfair.auth.enumeration;

import com.eastfair.annotation.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "UserRoleEnum", description = "用户角色")
public enum UserRoleEnum implements BaseEnum {
    /**
     * ADMIN="管理员"
     */
    ADMIN("管理员"),

    /**
     * STAFF="员工"
     */
    STAFF("员工")
    ;

    @ApiModelProperty(value = "描述")
    private String desc;

    /**
     * 根据当前枚举的name匹配
     */
    public static UserRoleEnum match(String val, UserRoleEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static UserRoleEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(UserRoleEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "NORMAL,WAIT_INIT,FORBIDDEN,WAITING,REFUSE,DELETE", example = "NORMAL")
    public String getCode() {
        return this.name();
    }
}
